package com.tdam.CommunicationManager;

import java.text.SimpleDateFormat;

import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class WebMailInfoHolder extends Holder
{
	private LinearLayout wrapper;
	private TextView txtMessage;
	private TextView txtWebMailDate;
	private ImageView imgEdit;
	@Override
	void fill(Object item) 
	{
		SimpleDateFormat formatter=new SimpleDateFormat("dd/MM/yyyy HH:mm");
		txtMessage.setText(((WebMailInfo)item).message);
		txtWebMailDate.setText(formatter.format(((WebMailInfo)item).timeStamp));
		if(((WebMailInfo)item).direction)
		{
			txtMessage.setBackgroundResource(R.drawable.web_mail_received);
			wrapper.setGravity(Gravity.RIGHT);
		}
		else
		{
			txtMessage.setBackgroundResource(R.drawable.web_mail_sent);
			wrapper.setGravity(Gravity.LEFT);
		}
		
		switch(((WebMailInfo)item).edit)
		{
			case NOT_EDIT:
				imgEdit.setVisibility(View.GONE);
				//txtWebMailDate.
				break;
			case EDIT_MARKED:
				imgEdit.setImageResource(R.drawable.delete_down);
				imgEdit.setVisibility(View.VISIBLE);
				break;
			case EDIT_NOT_MARKED:
				imgEdit.setImageResource(R.drawable.delete_up);
				imgEdit.setVisibility(View.VISIBLE);
				break;
				
		}		
	}

	@Override
	void link(View convertView)
	{
		txtMessage=(TextView) convertView.findViewById(R.id.txtWebMail);
		wrapper=((LinearLayout)convertView.findViewById(R.id.lnlWebMailMessage));
		txtWebMailDate=(TextView) convertView.findViewById(R.id.txtWebMailDate);
		imgEdit=(ImageView) convertView.findViewById(R.id.imgEdit);		
	}	
}				